var pipeLineId = "";
var pipepipeSegmentId = "";




// 管线选择点击事件
function pipeSegmentClick(id) {
	// 对管段ID进行诸如
	pipeSegmentId = id;

}


function getCrossClick() {
	// 获取一个起始点
	var startMileage = $("#startMileageId").val();
	
	// 获取一个终点
	var endMileage = $("#endMileageId").val();
	
	//将值放入隐藏域中
	$("#lineHiddenId").val(pipeLineId);
	$("#segmentHiddenId").val(pipeSegmentId);
	$("#startMileHiddenId").val(startMileage);
	$("#endMileHiddenId").val(endMileage);

	var url = window.config.controlServer + "/basedata/cross/findByCondition.json";
	//清空子节点
	$("#searchBody").empty();
	
	//$("#crossTableId").append("<ul class=\"ul-header\"><li class=\"w20\">管道名称</li><li class=\"w20\">管段名称</li><li class=\"w10\">所属穿跨越</li><li class=\"w20\">起始绝对距离</li><li class=\"w20\">终点绝对距离</li><li class=\"w10 no-right\">操作</li></ul>");
	
	var data = {"lineId":pipeLineId,"segmentId":pipeSegmentId,"startMileage":startMileage,"endMileage":endMileage};
	var map={"fillDiv":"#searchBody",
            "url":window.config.controlServer+"basedata/cross/findByCondition.json"};
	searchPage(map,data);
}




/**
 * 分页
 * @param current
 * @param pageCount
 * @param totalSize
 */
function commonPages(map){
    $("#commonsPage").createPage({
        current:parseInt(map.current),
        pageCount:parseInt(map.pageCount),
        totalSize:parseInt(map.totalSize),
        url:map.url,
        fillDiv:map.fillDiv,
        backFn:function(current,pageCount,totalSize,url,fillDiv){
            var resultMap={"current":parseInt(current),"isPage":"isPage","url":url,"fillDiv":fillDiv};
            var data={};
            searchPage(resultMap,data);
        }
    })
}

function searchPage(map,data){
	/*获取查询隐藏域的值*/
	var lineId = $("#lineHiddenId").val();
	var segmentId = $("#segmentHiddenId").val();
	var startMileage = $("#startMileHiddenId").val();
	var endMileage = $("#endMileHiddenId").val();
	
	if(lineId == "lineAll" || lineId == ""){
		lineId = null;
	}
	if(segmentId == "segmentAll" || segmentId == ""){
		segmentId = null;
	}
    var isPage=map.isPage;
    var current=1;
    if("isPage"==isPage){
        current=parseInt(map.current)
    }else{
        current=1;
    }
    var pageCount=$("#pageSelect").val();
    data.pageCount=parseInt(pageCount);
    data.current=current;
    /* */
    data.lineId = lineId;
    data.segmenetId = segmentId;
    data.startMileage = startMileage;
    data.endMileage = endMileage;
    
    $("#currentHiddenId").val(current);
    $("#pageCountHiddenId").val(pageCount);
    
    $.ajax({
        url:map.url,
        type:"post",
        dataType:"json",
        data:data,
        success:function(d){
            var p= d.main;
            var html='';
            for(var i=0;i< p.length;i++){
                html+=createProHtml(p[i],i);
            }
            
            $(map.fillDiv).html(html);
            if("isPage"==isPage){
                $("#totalSize").html(d.pageTotal);
            }else{
                $("#commonsPage").unbind();
                var resultMap={"current":1,"pageCount":pageCount,"totalSize":d.pageTotal,"url":map.url,"fillDiv":map.fillDiv};
                commonPages(resultMap);
            }
        }
    });
}


function createProHtml(p,i){
      var html='';

      			var gisId = p.GISID;
				//表主键ID
				var crossid=p.CROSSID;
				if(crossid==""||crossid==null){
					crossid="--";
				}
				
				//管线名称
				var LINENAME=p.LINENAME;
				if(""==LINENAME||null==LINENAME){
					LINENAME="-";
				}
				
				//管段名称
				var SEGMENTNAME=p.SEGMENTNAME;
				if(""==SEGMENTNAME||null==SEGMENTNAME){
					SEGMENTNAME="-";
				}
				//所属穿跨越	
				var AFFILIATIONCROSSING=p.AFFILIATIONCROSSING;
				if(""==AFFILIATIONCROSSING||null==AFFILIATIONCROSSING){
					AFFILIATIONCROSSING="-";
				}
				//"开始里程（m）"
				var STARTMILEAGE=p.STARTMILEAGE;
				if(""==STARTMILEAGE||null==STARTMILEAGE){
					STARTMILEAGE="-";
				}
				//起始参考点	
				var STARTREFERENCE=p.STARTREFERENCE;
				if(""==STARTREFERENCE||null==STARTREFERENCE){
					STARTREFERENCE="-";
				}
				//"起始参考点距离（m）"	
				var STARTREFERENCEDISTANCE=p.STARTREFERENCEDISTANCE;
				if(""==STARTREFERENCEDISTANCE||null==STARTREFERENCEDISTANCE){
					STARTREFERENCEDISTANCE="-";
				}
				//"终点里程（m）"
				var ENDMILEAGE=p.ENDMILEAGE;
				if(""==ENDMILEAGE||null==ENDMILEAGE){
					ENDMILEAGE="-";
				}
				//终止参考点	
				var ENDREFERENCE=p.ENDREFERENCE;
				if(""==ENDREFERENCE||null==ENDREFERENCE){
					ENDREFERENCE="-";
				}
				//"终止参考点距离（m）"
				var ENDREFERENCEDISTANCE=p.ENDREFERENCEDISTANCE;
				if(""==ENDREFERENCEDISTANCE||null==ENDREFERENCEDISTANCE){
					ENDREFERENCEDISTANCE="-";
				}
				//套管长度（m）
				var CASINGLENGTH=p.CASINGLENGTH;
				if(""==CASINGLENGTH||null==CASINGLENGTH){
					CASINGLENGTH="-";
				}
				//是否已填充
				var FILLEDIND=p.FILLEDIND;
				if(""==FILLEDIND||null==FILLEDIND){
					FILLEDIND="-";
				}
				//套管壁厚（mm）
				var WALLTHICKNESS=p.WALLTHICKNESS;
				if(""==WALLTHICKNESS||null==WALLTHICKNESS){
					WALLTHICKNESS="-";
				}
				//直径（mm）	
				var DIAMETER=p.DIAMETER;
				if(""==DIAMETER||null==DIAMETER){
					DIAMETER="-";
				}
				//密封类型	
				var SEALTYPE=p.SEALTYPE;
				if(""==SEALTYPE||null==SEALTYPE){
					SEALTYPE="-";
				}
				//是否绝缘	
				var INSULATORIND=p.INSULATORIND;
				if(""==INSULATORIND||null==INSULATORIND){
					INSULATORIND="-";
				}
				//是否短接	
				var SHORTEDIND=p.SHORTEDIND;
				if(""==SHORTEDIND||null==SHORTEDIND){
					SHORTEDIND="-";
				}
				//是否已排空
				var VENTEDIND=p.VENTEDIND;
				if(""==VENTEDIND||null==VENTEDIND){
					VENTEDIND="-";
				}
				//套管类型	
				var CASINGTYPE=p.CASINGTYPE;
				if(""==CASINGTYPE||null==CASINGTYPE){
					CASINGTYPE="-";
				}
				//防腐材料	
				var ANTISEPTICMATERIAL=p.ANTISEPTICMATERIAL;
				if(""==ANTISEPTICMATERIAL||null==ANTISEPTICMATERIAL){
					ANTISEPTICMATERIAL="-";
				}
				//填充材料	
				var FILLMATERIAL=p.FILLMATERIAL;
				if(""==FILLMATERIAL||null==FILLMATERIAL){
					FILLMATERIAL="-";
				}
				//记录人	
				var RECORDER=p.RECORDER;
				if(""==RECORDER||null==RECORDER){
					RECORDER="-";
				}
				//记录时间	
				var RECORDTIME=p.RECORDTIME;
				if(""==RECORDTIME||null==RECORDTIME){
					RECORDTIME="-";
				}
				//备注
				var CREATEREMARK=p.CREATEREMARK;
				if(""==CREATEREMARK||null==CREATEREMARK){
					CREATEREMARK="-";
				}
				
				//通过判断定义头样式
				var sty="bg-second";
				if(i%2){
					sty="bg-white";
				}
				//追加HTML
				html+='<div class=\"info-tr\"><ul class=\"ul-header '+ sty +'\"><li class=\"w20\">'
						+LINENAME+
						'</li><li class=\"w20\">'
						+SEGMENTNAME+
						'</li><li class=\"w10\">'
						+AFFILIATIONCROSSING+
						'</li><li class=\"w20\">'
						+ STARTMILEAGE+
						'</li><li class=\"w20\" dateStyle=\"default\">'
						+ENDMILEAGE+
						'</li><li class=\"w10 no-right\"><em class=\"xq-icon\"></em></li></ul><div class=\"show-ul none\"><ul class=\"show-list\"><li><span class=\"s1\">管道名称:</span><span class=\"s2\">'
						+LINENAME+
						'</span></li><li><span class="s1">管段名称:</span><span class="s2">'
						+SEGMENTNAME+
						'</span></li><li><span class=\"s1\">所属穿跨越:</span><span class=\"s2\">'
						+AFFILIATIONCROSSING+
						'</span></li><li><span class=\"s1\">开始里程（m）:</span><span class=\"s2\">'
						+STARTMILEAGE+
						'</span></li><li><span class=\"s1\">起始参考点:</span><span class=\"s2\">'
						+STARTREFERENCE+
						'</span></li><li><span class=\"s1\">起始参考点距离（m）:</span><span class=\"s2\">'
						+STARTREFERENCEDISTANCE+
						'</span></li><li><span class=\"s1\">终点里程（m）:</span><span class=\"s2\">'
						+ENDMILEAGE+
						'</span></li><li><span class=\"s1\">终止参考点:</span><span class=\"s2\">'
						+ENDREFERENCE+
						'</span></li><li><span class=\"s1\">终止参考点距离（m）:</span><span class=\"s2\">'
						+ENDREFERENCEDISTANCE+
						'</span></li><li><span class=\"s1\">套管长度（m）:</span><span class=\"s2\">'
						+CASINGLENGTH+
						'</span></li><li><span class=\"s1\">是否已填充:</span><span class=\"s2\">'
						+FILLEDIND+
						'</span></li><li><span class=\"s1\">套管壁厚（mm）:</span><span class=\"s2\">'
						+WALLTHICKNESS+
						'</span></li><li><span class=\"s1\">直径（mm）:</span><span class=\"s2\">'
						+DIAMETER+
						'</span></li><li><span class=\"s1\">密封类型:</span><span class=\"s2\">'
						+SEALTYPE+
						'</span></li><li><span class=\"s1\">是否绝缘:</span><span class=\"s2\">'
						+INSULATORIND+
						'</span></li><li><span class=\"s1\">是否短接:</span><span class=\"s2\">'
						+SHORTEDIND+
						'</span></li><li><span class=\"s1\">是否已排空:</span><span class=\"s2\">'
						+VENTEDIND+
						'</span></li><li><span class=\"s1\">套管类型:</span><span class=\"s2\">'
						+CASINGTYPE+
						'</span></li><li><span class=\"s1\">防腐材料:</span><span class=\"s2\">'
						+ANTISEPTICMATERIAL+
						'</span></li><li><span class=\"s1\">填充材料:</span><span class=\"s2\">'
						+FILLMATERIAL+
						'</span></li><li><span class=\"s1\">记录人:</span><span class=\"s2\">'
						+RECORDER+
						'</span></li><li><span class=\"s1\">记录时间:</span><span class=\"s2\">'
						+RECORDTIME+
						'</span></li><li class=\"last-li\"><span class=\"s1\">备注:</span><span class=\"s2\"><textarea placeholder=\"备注描述\" disabled=\"disabled\" readonly=\"readonly\">'
						+CREATEREMARK+
						'</textarea></span></li></ul></div></div>';
				 html += '<input type="hidden" name="data_gis_id" value = "'+ gisId+'"/>';
					return html;
}